package com.woniuxy.hotel.room.mapper;

import com.woniuxy.hotel.room.pojo.Hotel;
import com.woniuxy.hotel.room.pojo.HotelExample;
import com.woniuxy.hotel.room.pojo.HotelWithBLOBs;
import com.woniuxy.hotel.room.util.PageInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface HotelMapper {
    @SelectProvider(type = HotelSqlProvider.class, method = "countByExample")
    int countByExample(HotelExample example);
    
    @DeleteProvider(type = HotelSqlProvider.class, method = "deleteByExample")
    int deleteByExample(HotelExample example);
    
    @Delete({
            "update hotel",
            "set hotelFlag = 1",
            "where hotelid = #{hotelid,jdbcType=INTEGER}",
    })
    int deleteByPrimaryKey(Integer hotelid);
    
    @Insert({
            "insert into hotel (hotelid, hotelName, ",
            "hotelAddr, performance, ",
            "`describe`, hotelTrait)",
            "values (#{hotelid,jdbcType=INTEGER}, #{hotelname,jdbcType=VARCHAR}, ",
            "#{hoteladdr,jdbcType=VARCHAR}, #{performance,jdbcType=VARCHAR}, ",
            "#{describe,jdbcType=LONGVARCHAR}, #{hoteltrait,jdbcType=LONGVARCHAR})"
    })
    int insert(HotelWithBLOBs record);
    
    @InsertProvider(type = HotelSqlProvider.class, method = "insertSelective")
    int insertBySelective(HotelWithBLOBs record);
    
    @SelectProvider(type = HotelSqlProvider.class, method = "selectByExampleWithBLOBs")
    @Results({
            @Result(column = "hotelid", property = "hotelid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "hotelName", property = "hotelname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hotelAddr", property = "hoteladdr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "performance", property = "performance", jdbcType = JdbcType.VARCHAR),
            @Result(column = "describe", property = "describe", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelTrait", property = "hoteltrait", jdbcType = JdbcType.LONGVARCHAR)
    })
    List<HotelWithBLOBs> selectByExampleWithBLOBs(HotelExample example);
    
    @SelectProvider(type = HotelSqlProvider.class, method = "selectByExampleWithBLOBs")
    @Results({
            @Result(column = "hotelid", property = "hotelid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "hotelName", property = "hotelname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hotelAddr", property = "hoteladdr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "performance", property = "performance", jdbcType = JdbcType.VARCHAR),
            @Result(column = "describe", property = "describe", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelTrait", property = "hoteltrait", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelid", property = "evaluates",
                    many = @Many(select = "com.woniuxy.hotel.room.mapper.EvaluateMapper.selectByHotelId"))
    })
    List<HotelWithBLOBs> selectWithEvaluatesByExampleWithBLOBs(HotelExample example);
    
    @Select({
            "select",
            "hotelid, hotelName, hotelAddr, performance, `describe`, hotelTrait",
            "from hotel",
            "limit #{startIndex},#{limit} "
    })
    @Results({
            @Result(column = "hotelid", property = "hotelid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "hotelName", property = "hotelname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hotelAddr", property = "hoteladdr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "performance", property = "performance", jdbcType = JdbcType.VARCHAR),
            @Result(column = "describe", property = "describe", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelTrait", property = "hoteltrait", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelid", property = "evaluates",
                    many = @Many(select = "com.woniuxy.hotel.room.mapper.EvaluateMapper.selectByHotelId"))
    })
    List<HotelWithBLOBs> selectWithEvaluatesByLimitWithBLOBs(PageInfo pageInfo);
    
    @SelectProvider(type = HotelSqlProvider.class, method = "selectByExample")
    @Results({
            @Result(column = "hotelid", property = "hotelid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "hotelName", property = "hotelname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hotelAddr", property = "hoteladdr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "performance", property = "performance", jdbcType = JdbcType.VARCHAR)
    })
    List<Hotel> selectByExample(HotelExample example);
    
    @Select({
            "select",
            "hotelid, hotelName, hotelAddr, performance, `describe`, hotelTrait",
            "from hotel",
            "where hotelid = #{hotelid,jdbcType=INTEGER} and hotelFlag=0 "
    })
    @Results({
            @Result(column = "hotelid", property = "hotelid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "hotelName", property = "hotelname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hotelAddr", property = "hoteladdr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "performance", property = "performance", jdbcType = JdbcType.VARCHAR),
            @Result(column = "describe", property = "describe", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelTrait", property = "hoteltrait", jdbcType = JdbcType.LONGVARCHAR)
    })
    HotelWithBLOBs selectByPrimaryKey(Integer hotelid);
    
    @Select({
            "select",
            "hotelid, hotelName, hotelAddr, performance, `describe`, hotelTrait",
            "from hotel",
            "where hotelid = #{hotelid,jdbcType=INTEGER} and hotelFlag=0 "
    })
    @Results({
            @Result(column = "hotelid", property = "hotelid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "hotelName", property = "hotelname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hotelAddr", property = "hoteladdr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "performance", property = "performance", jdbcType = JdbcType.VARCHAR),
            @Result(column = "describe", property = "describe", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelTrait", property = "hoteltrait", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelid", property = "evaluates",
                    many = @Many(select = "com.woniuxy.hotel.room.mapper.EvaluateMapper.selectByHotelId"))
    })
    HotelWithBLOBs selectWithEvaluatesByPrimaryKey(Integer hotelid);
    
    @Select({
            "select",
            "*",
            "from hotel",
            "where hotelid = #{hotelid,jdbcType=INTEGER} and hotelFlag=0 "
    })
    @Results({
            @Result(column = "hotelid", property = "hotelid", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "hotelName", property = "hotelname", jdbcType = JdbcType.VARCHAR),
            @Result(column = "hotelAddr", property = "hoteladdr", jdbcType = JdbcType.VARCHAR),
            @Result(column = "performance", property = "performance", jdbcType = JdbcType.VARCHAR),
            @Result(column = "describe", property = "describe", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelTrait", property = "hoteltrait", jdbcType = JdbcType.LONGVARCHAR),
            @Result(column = "hotelid", property = "imgs",
                    many = @Many(select = "com.woniuxy.hotel.room.mapper.ImgMapper.selectByHotelId"))
    })
    HotelWithBLOBs selectWithImgByPrimaryKey(Integer hotelid);
    
    @UpdateProvider(type = HotelSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") HotelWithBLOBs record, @Param("example") HotelExample example);
    
    @UpdateProvider(type = HotelSqlProvider.class, method = "updateByExampleWithBLOBs")
    int updateByExampleWithBLOBs(@Param("record") HotelWithBLOBs record, @Param("example") HotelExample example);
    
    @UpdateProvider(type = HotelSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") Hotel record, @Param("example") HotelExample example);
    
    @UpdateProvider(type = HotelSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(HotelWithBLOBs record);
    
    @Update({
            "update hotel",
            "set hotelName = #{hotelname,jdbcType=VARCHAR},",
            "hotelAddr = #{hoteladdr,jdbcType=VARCHAR},",
            "performance = #{performance,jdbcType=VARCHAR},",
            "`describe` = #{describe,jdbcType=LONGVARCHAR},",
            "hotelTrait = #{hoteltrait,jdbcType=LONGVARCHAR}",
            "where hotelid = #{hotelid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKeyWithBLOBs(HotelWithBLOBs record);
    
    @Update({
            "update hotel",
            "set hotelName = #{hotelname,jdbcType=VARCHAR},",
            "hotelAddr = #{hoteladdr,jdbcType=VARCHAR},",
            "performance = #{performance,jdbcType=VARCHAR}",
            "where hotelid = #{hotelid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Hotel record);
    
}